package com.qfedu.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qfedu.entity.AuthEntity;
import com.qfedu.pojo.AuthPojo;
import com.qfedu.service.AuthService;
import com.qfedu.util.Ajaxd;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
public class AuthController {
    @Autowired
    private AuthService authService;

    @RequestMapping("/queryAllPower.do")
    public  String doQueryAllPower(AuthEntity authEntity, HttpServletRequest request){
        PageHelper.startPage(authEntity.getPageNum(),authEntity.getPageSize());
        List<AuthPojo> authPojos = authService.queryAllAuth(authEntity);
        PageInfo<AuthPojo> pageInfo=new PageInfo<AuthPojo>(authPojos);
        request.setAttribute("auname",authEntity.getAuname());
        request.setAttribute("pageinfo",pageInfo);
        return "auth/auth-list";
    }

    @RequestMapping("/deleteAuth.do")
    @ResponseBody
    public Ajaxd doDeleteAuth(String auidstr){
        Ajaxd ajaxd = new Ajaxd();
        String substring = auidstr.substring(0, auidstr.lastIndexOf(","));
        Boolean flag = authService.deleteAuthById(substring);
        if (flag){
            ajaxd.setFlag(true);
        }else {
            ajaxd.setFlag(false);
        }
        return ajaxd;
    }

@RequestMapping("/editAuth.to")
    public String doEditAuth(){

        return "auth/auth-edit";
}
}
